package concert;

import org.aspectj.lang.ProceedingJoinPoint;
import org.aspectj.lang.annotation.*;
import org.springframework.stereotype.Component;

@Component  // 这个是必须的！！
@Aspect
public class Audience {
    @Before("execution(**concert.Performance.perform(..))")    // 该注解声明了silenceCellPhones()需要应用到的Pointcut。
    public void silenceCellPhones() {
        System.out.println("Silencing cell phones");
    }

    @Before("execution(**concert.Performance.perform(..))")
    public void takeSeats() {
        System.out.println("Taking seats");
    }

    @AfterReturning("execution(**concert.Performance.perform(..))")
    public void applause() {
        System.out.println("CLAP CLAP CLAP!!!");
    }

    @AfterThrowing("execution(**concert.Performance.perform(..))")
    public void demandRefund() {
        System.out.println("Demanding a refund");
    }


    //-------------------------------------------------------------------------------
    @Pointcut("execution(**concert.Performance.perform(..))")
    public void perform() {
        System.out.println("进入切点");
    }

    @Before("perform()")
    public void beforeExcute() {
        System.out.println("前置执行");
   ;
    }

    @After("perform()")
    public void afterExcute(){
        System.out.println("后置执行");
    }

    @Around("perform()")
     public void aroundExcute(ProceedingJoinPoint jp){
        try {
            jp.proceed();
        } catch (Throwable throwable) {
            throwable.printStackTrace();
        }
    }






}